<?php

    require ( 'init.inc.php' );
    require ( 'checkadmin.inc.php');
    require ( __COMM_PATH . 'pagecontrol.inc.php' );
    require ( __COMM_PATH . 'checkform.func.php' );
    require ( __CLASS_PATH . 'page_edit.class.php' );
    require ( __CLASS_PATH . 'tree.class.php' );

    // -------------------------------------------------------
    // 接收传递过来的变量
    // -------------------------------------------------------
    $action = $_REQUEST["action"];
    $id     = addslashes($_REQUEST["id"]);

    // -------------------------------------------------------
    // 页面基本设置
    // -------------------------------------------------------
    $page_title   = $ptitle["imgs_edit"];
    $page_type    = "edit";
    $display_page = "imgs_edit.htm";
    $table_name   = "{$tablepre}imgs";
    $condition    = "WHERE `id`='{$id}'";
    $back_page    = "imgs_list.php?sortby={$_GET['sortby']}&oexp={$_GET['oexp']}&page={$_GET['page']}&imgs_classid={$_GET['imgs_classid']}&keyword={$_GET['keyword']}";


    // -------------------------------------------------------
    // 保存编辑数据
    // -------------------------------------------------------
    if ($action=="submit") {
        $imgs_classid = check_numeric($_POST["imgs_classid"],$clang[imgs_classid]);
        if ($imgs_classid==0) feedback($cmsg['imgs_class_null']);
        $imgs_name = dhtmlspecialchars(check_empty($_POST["imgs_name"],$clang[imgs_name]));
        $imgs_title = dhtmlspecialchars($_POST["imgs_title"]);
        $imgs_url = dhtmlspecialchars($_POST["imgs_url"]);
        $imgs_thumb = dhtmlspecialchars(check_empty($_POST["imgs_thumb"],$clang[imgs_thumb]));
        
        $fields_arr = array(
            "imgs_classid" => $imgs_classid,
            "imgs_name" => $imgs_name,
            "imgs_title" => $imgs_title,
            "imgs_url" => $imgs_url,
            "imgs_thumb" => $imgs_thumb,
            "imgs_desc" => dhtmlspecialchars($_POST["imgs_desc"]),
            "imgs_detail" => $_POST["imgs_detail"],
            "imgs_tags" => dhtmlspecialchars($_POST["imgs_tags"]),
            "imgs_isvalid" => intval($_POST["imgs_isvalid"]),
            "imgs_istop" => intval($_POST["imgs_istop"]),
            "imgs_index" => intval($_POST["imgs_index"]),
            "imgs_pubtime" => date ("Y-m-d H:i:s", strtotime($_POST["imgs_pubtime"])),
            "imgs_author" => dhtmlspecialchars($_POST["imgs_author"]),
        );
    }

    // -------------------------------------------------------
    // 执行页面处理
    // -------------------------------------------------------
    show_page_head($page_type, $page_title);
    $pedit = new PageEdit($page_title, $back_page, $page_type);
    $pedit->SetParam($table_name, $condition);
    $tree = new Tree("{$tablepre}imgs_class", 0);
    $tpl->assign('imgs_classid_box', $tree ->_makeSelBox("imgs_classid", $pedit->QueryRow["imgs_classid"], true, "")); // 生成下拉列表
    $pedit->UpdateData($fields_arr);
    $pedit->TplParse($display_page);
    show_page_foot();
    $db->close();
?>